package CodeBlock;

public class codeblock_ {
    public static void main(String[] args) {
//        Movie movie1 = new Movie("流浪地球");
//
//        Movie movie2 = new Movie("流浪地球2", 20);
//
//        Movie movie3 = new Movie("流浪地球3", 50, "吴京");

        //1.创建实例对象的时候new
        //AA aa = new AA();
        //2.创建子类对象实例，父类也会被加载
       // BB bb = new BB();
        //3.使用类的静态成员的时候
        //System.out.println(CC.count);
        //CC cc = new CC();
        CC cc = new CC();
    }
}


class CC{
    public int n1 = 20;
    public static int count = 10;
    private static int n2 = 10;

    static {
        System.out.println(n2);
        System.out.println("CC静态代码块被调用");
    }

    //普通代码块只有在创建对象实例的时候才会被调用，创建一次，调用一次，
    // 如果只是使用静态变量时，普通代码块不会被调用
    {
        System.out.println(n2);
        System.out.println("CC的普通代码块");
    }
}
class BB extends AA{
    static {
        System.out.println("BB静态代码块被调用");
    }
}
class AA{
    //静态代码块，在类加载的时候被调用
    //类什么时候被加载：
    //1.创建实例对象的时候new
    //2.创建子类对象实例，父类也会被加载
    //3.使用类的静态成员的时候
    static {
        System.out.println("AA静态代码块被调用");
    }
}


class Movie{
    private String name;
    private double price;
    private String director;

    //代码块，不管调用那个构造器，都会先调用代码块
    {
        System.out.println("1");
        System.out.println("2");
        System.out.println("3");

    };

    public Movie(String name) {
        System.out.println("Movie(String name)被调用");
        this.name = name;
    }

    public Movie(String name, double price) {
        System.out.println("Movie(String name, double price)被调用");
        this.name = name;
        this.price = price;
    }

    public Movie(String name, double price, String director) {
        System.out.println("Movie(String name, double price, String director)被调用");
        this.name = name;
        this.price = price;
        this.director = director;
    }


}
